#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> addToArrayForm(vector<int>& num, int k)
    {
        vector<int> res;

        int r = 0;
        int sum = 0;
        while (k || !num.empty())
        {
            if (!num.empty())
            {
                sum = k % 10 + num.back() + r;
                num.pop_back();
            }
            else
                sum = k % 10 + r;
            r = sum / 10;
            sum %= 10;
            res.push_back(sum);
            k /= 10;
        }

        if (r)   res.push_back(r);

        reverse(res.begin(), res.end());

        return res;
    }
};